﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    processor.moveToThread(new QThread(this));
    //线程启动，则触发线程中的startVideo()
    connect(processor.thread(),SIGNAL(started()),&processor,SLOT(startVideo()));
    //接收由线程发出的含参信号，ui的label中显示图像
    connect(&processor,SIGNAL(inDisplay(QPixmap)),ui->inVideo,SLOT(setPixmap(QPixmap)));
    connect(&processor,SIGNAL(outDisplay(QPixmap)),ui->outVideo,SLOT(setPixmap(QPixmap)));

    processor.thread()->start();    //启动线程

    //方式二的代码
    //processor.start();  //启动线程
}

MainWindow::~MainWindow()
{
    processor.stopVideo();
    processor.thread()->quit();
    processor.thread()->wait();

    //方式二的代码
    //processor.requestInterruption();   //请求线程停止
    //processor.wait();                  //等待线程完成清理并安全地执行完毕

    delete ui;      //此行放最后。保证在失控之前，该释放的释放掉
}
